<template>
  <div style="height: 50px;line-height: 50px;border-bottom: 1px solid #aaa ;display: flex">
    <div style="width: 200px;font-size: 20px; font-weight: bold;color: cornflowerblue;margin-left: 10px">后台管理</div>
    <div style="flex: 1px"></div>
    <div style="width: 150px">
      <img class="el-img"  src="../assets/JKS.png">
      <el-dropdown>
        <span class="el-dropdown-link" >
          <span v-for="item in toSonData" :key="item.id">
            {{item.username}}
          </span>
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人信息</el-dropdown-item>
          <el-dropdown-item @click.native="returnLogin">退出系统</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import {mapMutations} from "vuex";
export default {
  name: 'Header',
  props:["toSonData"],//获取父页面传递过来的值
  methods: {
    ...mapMutations(['delToken']),
    returnLogin(){
      this.delToken({token:''});
      sessionStorage.clear();//清空sessionStorage中所有信息
      this.$router.replace('/');//replace 可禁止返回上个页面
      this.$message({message: "退出成功", type: 'success'});
    }
  }
}
</script>


<style scoped>
.el-img{
  float: left;
  width: 35px;
  height: 35px;
  margin-right:10px;
  margin-top: 5px;
  border-radius: 50%;
}

</style>
